package com.gouaixin.bee.beeframework2.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.util.AbToastUtil;
import com.bx.pay.BXPay;
import com.bx.pay.backinf.PayCallback;
import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.tool.mLog;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/3/10.
 */
//确认订单（VIP）
public class B22_querendingdanActivity extends FragmentActivity {
    Context context = B22_querendingdanActivity.this;

    //顶部
    ImageView back;//返回
    TextView title;//标题

    TextView orderTv, priceTv;//订单名、订单价格
    CheckBox tuijian01Cb, tuijian02Cb, tuijian03Cb, tuijian04Cb;//更多推荐的多选框
    TextView queding;//确定


    String order = "";//订单名
    String price = "";//订单价格

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.b22_querendingdan);

        initView();

        initIntent();

        setData();

        setListener();
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        title = (TextView) findViewById(R.id.title);
        orderTv = (TextView) findViewById(R.id.tv02);
        priceTv = (TextView) findViewById(R.id.tv03);
        tuijian01Cb = (CheckBox) findViewById(R.id.man01);
        tuijian02Cb = (CheckBox) findViewById(R.id.man02);
        tuijian03Cb = (CheckBox) findViewById(R.id.man03);
        tuijian04Cb = (CheckBox) findViewById(R.id.man04);
        queding = (TextView) findViewById(R.id.queding);
    }

    private void initIntent() {
        Intent it = getIntent();
        order = it.getStringExtra("order");
        price = it.getStringExtra("price");

    }

    private void setData() {
        orderTv.setText(order);
        priceTv.setText("￥" + price);
    }

    private void setListener() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AbToastUtil.showToast(context, "此处假设已经完成支付，直接下一步");
                tiaozhuanBaoyue();
//                View mView = LayoutInflater.from(context).inflate(R.layout.dialog_pay, null);
//                AbDialogUtil.showDialog(mView);
//
//                TextView pay_phone= (TextView) mView.findViewById(R.id.pay_phone);
//
//                pay_phone.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        AbDialogUtil.removeDialog(context);
//                        initWeiPai();
//
//                    }
//                });
            }
        });

    }


    private void initWeiPai() {
        String payCode = "0001";

        BXPay bxpay = new BXPay(this);
        bxpay.init(this);
        Map<String, String> devPrivate = new HashMap<String, String>();
        devPrivate.put("开发者要传的KEY值", "开发者要传的VALUE值");
        bxpay.setDevPrivate(devPrivate);//setDevPrivate方式是非必选
        bxpay.pay(payCode, new PayCallback() {

            @Override
            public void pay(Map resultInfo) {
                mLog.e("weipai:resultInfo=" + resultInfo.toString());

                String result = (String) resultInfo.get("result");//描述：  result返回微派支付结果 目前有如下几个状态1、success:成功支付，表示支付成功。2、pass:表示在付费周期里已经成功付费，已经是付费用户。3、pause:表示计费点暂时停止。4、error:本地联网失败、获取不到支付参数等情况。5、fail:支付失败。6、cancel:表示用户取消支付。
                String payType = (String) resultInfo.get("payType");//描述：支付方式类型   目前有如下几个类型   1、	wpay:微派短信支付 。2、	alipay:支付宝支付。3、	czk:充值卡支付。4、	dk:点卡支付。5、	balance：余额支付。6、	uppay:银联支付。
                String payCode = (String) resultInfo.get("payCode");//描述：计费点编号
                String price = (String) resultInfo.get("price");//描述：价格
                String logCode = (String) resultInfo.get("logCode");//订单编号
                String showMsg = (String) resultInfo.get("showMsg");//支付结果详细描述提示
                //以下是非必需調用
                new AlertDialog.Builder(context).setTitle("支付结果返回：")
                        .setMessage(Html.fromHtml("支付结果：" + result + "<br>" +
                                "支付类型：" + payType + "<br>" +
                                "计费点：" + payCode + "<br>" +
                                "计费价格：" + price + "<br>" +
                                "订单编号：" + logCode + "<br>" +
                                "支付结果描述：" + showMsg + "<br>"))
                        .setPositiveButton("确定", null).show();

//
            }
        });

    }


    /**
     * 弹出邀请包月的对话框
     */

    AlertDialog.Builder builder;
    AlertDialog alertDialog;

    private void tiaozhuanBaoyue() {

        mLog.e("弹出包月服务对话框");
        View mView = LayoutInflater.from(context).inflate(R.layout.dialog_vipfuwu, null);
//        AbDialogUtil.showDialog(mView);

        builder = new AlertDialog.Builder(context, R.style.my_dialog);
//        builder.setView(mView);
        alertDialog = builder.create();

        alertDialog.setView(mView, 0, 0, 0, 0);
        alertDialog.setCancelable(false);
        alertDialog.show();

        TextView title = (TextView) mView.findViewById(R.id.title);
        TextView content = (TextView) mView.findViewById(R.id.content);
        TextView quxiao = (TextView) mView.findViewById(R.id.quxiao);
        TextView kaitong = (TextView) mView.findViewById(R.id.kaitong);

        title.setText("包月服务");
        content.setText("立即开通包月服务，和心爱的她畅聊吧");

        quxiao.setVisibility(View.GONE);
        kaitong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent it = new Intent().setClass(context, B15_faxinBaoyueActivity.class);
                startActivity(it);
                alertDialog.cancel();
            }
        });

    }


}
